package com.aoxon.cargo.activity.n;

import java.util.ArrayList;
import java.util.List;

import psnl.littlemouse.vpwid.BaseFragment;
import psnl.littlemouse.vpwid.FragmentsAdapter;
import psnl.littlemouse.vpwid.TabInfo;
import psnl.littlemouse.vpwid.TabInfo.TipType;
import psnl.littlemouse.vpwid.TitleIndicator;
import psnl.littlemouse.vpwid.VPWIDActivity;
import android.app.Activity;
import android.content.Intent;
import android.support.v4.view.ViewPager;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.TextView;

import com.aoxon.cargo.R;
import com.aoxon.cargo.activity.PurGoodsSearchActivity;
import com.aoxon.cargo.activity.fragment.NewPurFragment;
import com.aoxon.cargo.activity.fragment.PurFragment;
import com.aoxon.cargo.keydown.ExitApplication;
import com.aoxon.cargo.service.MyServiceFactory;

public class IndexActivity extends VPWIDActivity {

    private ImageView ivGPSButton;
    private TextView  ivSearchGoodsButton;
    @Override
    protected void setContentViewLayout(Activity activity) {
        // TODO Auto-generated method stub
        activity.setContentView(R.layout.pur_index);
    }

    @Override
    protected void setupUI() {

        ivGPSButton = (ImageView) findViewById(R.id.ivPurIndexGPS);
        ivSearchGoodsButton = (TextView) findViewById(R.id.tvPurIndexSearchButton);
        ivGPSButton.setOnClickListener(myClickListener);
        ivSearchGoodsButton.setOnClickListener(myClickListener);
        setNeedPortLine(false);
    }

    @Override
    protected void initIndicator() {
        // TODO Auto-generated method stub
        indicator = (TitleIndicator) findViewById(R.id.mTitle);
    }

    @Override
    protected void initViewPage() {
        // TODO Auto-generated method stub
        viewPager = (ViewPager) findViewById(R.id.mViewPager);
        viewPager.setOffscreenPageLimit(0);
    }

    @Override
    protected void setDefault_color_resId() {
        // TODO Auto-generated method stub
        default_color_resId = R.color.dark;
    }

    @Override
    protected void setSelected_color_resId() {
        // TODO Auto-generated method stub
        selected_color_resId = R.color.blue;
    }

    @Override
    protected void setTabsAndAdapter() {
        // TODO Auto-generated method stub
        tabs = new ArrayList<TabInfo>();
        tabs.add(new TabInfo("精选", R.layout.vpwid_tab_item, R.id.tab_name, R.id.tip, TipType.textview));
        tabs.add(new TabInfo("上新", R.layout.vpwid_tab_item, R.id.tab_name, R.id.tip, TipType.textview));

        List<BaseFragment> pages = new ArrayList<BaseFragment>();
        pages.add(new PurFragment(tabs.get(0), MyServiceFactory.HOT_GOODS, true));
        pages.add(new PurFragment(tabs.get(0), MyServiceFactory.NEW_GOODS,false));
        adapter = new FragmentsAdapter(this, getSupportFragmentManager(), pages);
    }

    OnClickListener         myClickListener = new OnClickListener() {

                                                @Override
                                                public void onClick(View v) {
                                                    // TODO Auto-generated method stub
                                                    Intent intent = null;
                                                    switch (v.getId()) {
                                                        case R.id.ivPurIndexGPS:
                                                            PurMapActivity.LAUNCH_MODE = PurMapActivity.MY_LOC_AND_SUPLIST;
                                                            intent = new Intent(getBaseContext(), PurMapActivity.class);
                                                            startActivity(intent);
                                                            IndexActivity.this.finish();
                                                            break;
                                                        case R.id.tvPurIndexSearchButton:
                                                            intent = new Intent(getBaseContext(),
                                                                                PurGoodsSearchActivity.class);
                                                            startActivity(intent);
                                                            IndexActivity.this.finish();
                                                            break;
                                                        default:
                                                            break;
                                                    }
                                                }
                                            };

    private ExitApplication exitApplication = new ExitApplication(this);

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        return exitApplication.onKeyDown(keyCode, event);
    }

}
